<?php

namespace App\Http\Resources;

use Illuminate\Http\Resources\Json\JsonResource;

class ShopResource extends JsonResource
{
    /**
     * Transform the resource into an array.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return array|\Illuminate\Contracts\Support\Arrayable|\JsonSerializable
     */
    public function toArray($request)
    {
        return [
            'id'=>$this->id,
            'name'=>$this->name,
            'addr'=>$this->addr,
            'phone'=>$this->phone,
            'username'=>$this->username,
            'img'=>env('APP_URL').'/uploads/'.$this->img,
            'lunboimg'=>$this->when(!empty($this->imgs),function (){
                $imgs=json_decode($this->imgs,true);
                foreach ($imgs as $imgkey=>$img){
                    $imgs[$imgkey]=env('APP_URL').'/uploads/'.$img;
                }
                return $imgs;
            })
        ];
    }
}
